<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>商家管理</title>
    <link rel="stylesheet" type="" href="http://at.alicdn.com/t/font_elc53nn4q4f2mx6r.css">
    <link rel="stylesheet" type="" href="../../sq/css/home.css">
</head>
<body>
    <header>
        <div class="top">
            <div class="item">
                <a href="erweima.html">
                <div><i class="icon iconfont icon-shoukuan" style="font-size: 28px;margin-top: 0"></i></div>
                <p>收款</p>
                    </a>
            </div>
            <div class="item" id="store">
            </div>
            <div class="item">
                <a href="admin.html"><div><i class="icon iconfont icon-dianpuguanli"></i></div>
                <p>店铺管理</p></a>
            </div>
            <a href="javascript:;" class="loginOut" ></a>
        </div>
        <div class="bot">
            <div class="headerFoot"><a href="sq_brokerage.html"><i class="icon iconfont icon-tuiguang"></i><p>我的推广</p></a></div>
            <div class="headerFoot"><a href="offline_list_order.html"><i class="icon iconfont icon-dingdanliebiao"></i><p>我的订单</p></a></div>
            <div class="headerFoot"><a href="check_vr_code.html"><i class="icon iconfont icon-verification"></i><p>验证码兑换</p></a></div>
        </div>
    </header>
    <div class="main">

    </div>
    <div class="list_loading" style="display: none"><i></i><span>努力加载中...</span></div>
    <div class="nodata">没有更多订单了</div>
</body>
</html>
<script type="text/html" id="top">
    <% var store_info = datas.store_info; %>
    <% if(store_info.store_avatar) { %>
              <img src="<%=store_info.store_avatar %>" alt="">
    <% }else{ %>
             <img src="../../images/default_store_avatar.png" alt="">
    <% } %>
    <p><%=store_info.store_name %></p>
</script>
<script type="text/html" id="list">
    <% for(var i = 0;i<list.length;i++){ %>
    <div class="detail">
        <div class="detail_head">
            <div style="width:90%;margin: 0 auto;padding: 15px">
                <img src="../../sq/img/order.png" alt="">
                <div class="order">
                    <div>订单</div>
                    <p><%=list[i].time%></p>
                </div>
                <div class="confirm" id="confirm_<%=list[i]['order_id']%>">
                    <% if (list[i].order_state==20){ %>
                        <% if(list[i].recive==0) { %>
                             等待确认
                        <% } %>
                        <% if(list[i].recive==1) { %>
                           <span style="color: #666">已确认</span>
                        <% } %>
                    <% } %>
                    <% if (list[i].order_state==10){ %>
                        <span style="color: #666">待支付</span>
                    <% } %>
                    <% if (list[i].order_state==0){ %>
                    <span style="color: #666">已取消</span>
                    <% } %>
                </div>
            </div>
        </div>
        <a href="reslute.html?paysn=<%=list[i].order_sn%>" style="color: #666">
        <div>
            <center>
                <div>￥<%=list[i].order_amount%></div>
                <p><%=list[i].buyer_name%> <span style="color:#f98524"><% if(list[i].payment_code=='navgator') { %>线下支付<% }%><% if(list[i].payment_code=='predeposit') { %>余额支付<% }%><% if(list[i].payment_code=='wx_jsapi') { %> 微信支付 <% } %></span></p>
            </center>
        </div>
        </a>
        <div class="detail_foot">
            <div>
                订单编号:<%=list[i].order_sn%>
            </div>
            <% if (list[i].order_state==20){ %>
                <% if(list[i].recive==0) { %>
                <div class="querenshouhuo" id="btn_<%=list[i]['order_id']%>" data-id="<%=list[i]['order_id']%>">
                    确认收款
                </div>
                <% } %>
            <% } %>
        </div>
    </div>
    <% } %>
</script>
<script type="text/javascript" src="../../js/config.js"></script>
<script type="text/javascript" src="../../js/zepto.min.js"></script>
<script type="text/javascript" src="../../js/template.js"></script>
<script type="text/javascript" src="../../js/startmove.js"></script>
<script type="text/javascript" src="../../js/simple-plugin.js"></script>
<script type="text/javascript" src="../../js/common.js"></script>
<script>
    var key = getCookie('key');
    var storeid = getCookie('sqstoreid');
            $(function(){
                if(!key||!storeid){
                    window.location.href = '/sq/login.html';
                }

                // 请求店铺信息
                $.ajax({
                     type:'get',
                     url:ApiUrl + "/index.php?act=store&op=getSqStoreInfo",
                     data:{key:key,sqstore_id:storeid},
                     dataType:"json",
                     success:function(data){
                         if (result.code == 400) {
                             delCookie('key');
                             delCookie('store_id');
                             location.reload();
                         }
                         var store = template.render('top',data);
                           $("#store").html(store);
                     }
                })

                // 获取订单信息
                $.ajax({
                    type:"GET",
                    url:ApiUrl+"/index.php?act=store&op=offline_order_list",
                    dataType:"json",
                    data:{key:key,store_id:storeid},
                    success:function(res){
                        if (res){
                            $('.main').html(template.render('list',res));
                        }else{
                            $('.main').html("<p class='no-data'>赞无数据</p>");
                        }
                    }
                })

                $('.loginOut').on('click', function () {
                    delCookie("sqstoreid");
                    window.location.href = "/sq/login.html";
                })

                /**
                 *  确认收款
                 * */
                $(document).on('click','.querenshouhuo',function(e){

                      var id = $(this).attr('data-id');

                      $.sDialog({
                        skin:"red",
                        content:"确认要收款吗？",
                        okBtn:true,
                        cancelBtn:true,
                        okFn: toSubmit, //点击确定按钮执行的函数
                      });

                      /**
                       * 发送收款请求
                       * */
                      function toSubmit(){
                          $.ajax({
                              type:"post",
                              url:ApiUrl+"/index.php?act=store&op=store_recive",
                              data:{key:key,order_id:id},
                              dataType:"json",
                              success:function(data){
                                    if(data['code']==200){
                                          data = data.datas;
                                          if(data['status']==200){
                                                window.location.href = 'reslute.html?paysn='+data.paySn+"&callback=1";
                                          }else{
                                                creatLayout('收款失败');
                                          }
                                    }else{

                                    }
                              }
                          })
                      }
                });
            })

            var isLock = false; // 锁定状态
            var page = 1;
            /**
             * 下拉到底刷新
             */
            $(window).scroll(function () {
                var windowheight=$(window).height();//窗口高度
                var scrolltop=$('body').scrollTop();//滚动条高度
                var eh=$(document).height();//文本高度
                if(parseInt(windowheight+scrolltop+1)>=eh && isLock==false){
                    document.getElementsByClassName('list_loading')[0].style.display =' block';
                    isLock = true;
                    page+=1;
                    // 获取订单信息
                    $.ajax({
                        type:"GET",
                        url:ApiUrl+"/index.php?act=store&op=offline_order_list&page="+page,
                        dataType:"json",
                        data:{key:key,store_id:storeid},
                        success:function(res){
                            document.getElementsByClassName('list_loading')[0].style.display =' none';
                            isLock = false;
                            if (res){
                                $('.main').html($('.main').html()+template.render('list',res));
                            }else{
                                isLock = true;
                                $('.nodata').show();
                            }
                        }
                    })
                }
            })

            function calcRem() {
                var http = document.getElementsByTagName("html")[0];
                var w = document.documentElement.clientWidth;
                http.style.fontSize = w / 32 + "px";
            }
            calcRem();
            window.onresize = function() {
                calcRem();
            };
</script>